#ifndef _Z9_HTTP_H
#define _Z9_HTTP_H

#include "util/z9_bytechunk.h"
#include "util/z9_string.h"

#define Z9_HTTP_SLOTS_SIZE 63

typedef struct z9_http_hash_item z9_http_hash_item;
typedef struct z9_http_header_iterator z9_http_header_iterator;

struct z9_http_hash_item {
	z9_http_hash_item *next;
	z9_string         *field;
	z9_string         *value;
};

typedef struct {
	uint32_t        		   refcount;
	int32_t                    method;	
	z9_string                *status;
	z9_string                *url;
	z9_bytebuffer            *body;
	z9_http_hash_item        *headers[Z9_HTTP_SLOTS_SIZE];
}z9_http_packet;

struct z9_http_header_iterator {
	int32_t              curidx;
	z9_http_packet     *http_packet;
	z9_http_hash_item  *current;
	const char          *field;
	const char          *value;	
};

const char *z9_http_method2name(int32_t method);
int32_t z9_http_name2method(const char *name);

int32_t z9_http_is_vaild_header_iterator(z9_http_header_iterator *);
int32_t z9_http_header_iterator_next(z9_http_header_iterator *);
int32_t z9_http_header_begin(z9_http_packet*, z9_http_header_iterator*);

z9_http_packet *z9_http_packet_new();
void z9_http_packet_release(z9_http_packet *http_packet);
z9_http_packet *z9_http_packet_retain(z9_http_packet *http_packet);
int32_t z9_http_get_method(z9_http_packet *http_packet);
const char *z9_http_get_url(z9_http_packet *http_packet);
const char *z9_http_get_status(z9_http_packet *http_packet);
const char *z9_http_get_header(z9_http_packet *http_packet, const char *field);
z9_bytebuffer *z9_http_get_body(z9_http_packet *http_packet);
void z9_http_set_method(z9_http_packet *http_packet, int32_t method);
void z9_http_set_url(z9_http_packet *http_packet, z9_string *url);
void z9_http_set_status(z9_http_packet *http_packet, z9_string *status);
int32_t z9_http_set_header(z9_http_packet *http_packet, z9_string *field, z9_string *value);
int32_t z9_http_append_body(z9_http_packet *http_packet, const char *str, size_t size);



/*
typedef struct {
	z9_http_packet *http_packet;	
}z9_http_request;

typedef struct {
	z9_http_packet *http_packet;
}z9_http_response;

z9_http_request *z9_http_request_new(z9_http_packet *http_packet);
void z9_http_request_destroy(z9_http_request *);
z9_http_request *z9_http_request_clone(z9_http_request *);

int32_t z9_http_request_get_method(z9_http_request *);
const char *z9_http_request_get_url(z9_http_request *);
const char *z9_http_request_get_status(z9_http_request *);
const char *z9_http_request_get_header(z9_http_request *,const char *field);
z9_bytebuffer *z9_http_request_get_body(z9_http_request *);


z9_http_response *z9_http_response_new();
void z9_http_response_destroy(z9_http_response *);
void z9_http_response_set_method(z9_http_response *,int32_t method);
void z9_http_response_set_url(z9_http_response *,z9_string *url);
void z9_http_response_set_status(z9_http_response *,z9_string *status);
int32_t z9_http_response_set_header(z9_http_response *,z9_string *field,z9_string *value);
int32_t z9_http_response_add_body(z9_http_response *,const char *str,size_t size);
*/


#endif